package com.study.signin_demo2.class03;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @author whx
 * @date 2022/2/21
 */
public class C08_Lambda02 {

    public static void main(String[] args) {
        User user1 = new User(1L,"mike",23);
        User user2 = new User(2L,"benjamin",25);
        List<User> userList = new ArrayList<>();
        userList.add(user2);
        userList.add(user1);
        userList.sort(new UserComparator());
        System.out.println(userList);

        System.out.println("------");

        // lambda表达式写法
        userList.sort((o1,o2) -> o1.getAge()-o2.getAge());
        // 简化写法
        userList.sort(Comparator.comparingInt(User::getAge));

        // 作业2：现有用户数据如下，先根据用户年龄排序，如果年龄一致，根据用户名的字符排序，比如用户名a>b,ab>ac
        // 用户数据
//        User user1 = new User(1L,"mike",23);
//        User user2 = new User(2L,"benjamin",25);
//        User user3 = new User(3L,"ben",25);
//        User user4 = new User(4L,"mick",23);
    }
}
